Public Class TimeSheetHoursReport
    Private WithEvents _aMetaDataTableChild As CommonExt.MetaDataTable
    Private WithEvents _aMetaDataTable As CommonExt.MetaDataTable
    Private WithEvents _aDataset As New DataSet("ReportDataSet")
    Private _aQueryName As String

    Private _paramOrderNo As String
    Public Property ParamOrderNo() As String
        Get
            Return _paramOrderNo
        End Get
        Set(ByVal value As String)
            _paramOrderNo = value
        End Set
    End Property




    Private Sub PurchaseOrder_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles Me.BeforePrint


        If Not String.IsNullOrEmpty(ParamOrderNo) Then
            'Get MetaData by QueryName
            _aQueryName = "RptTime"
            Dim _aQueryNameChild As String = "RptTimeDetail"
            Dim mq As MetaQuery = MetaQuery.GetMetaQueryByName(_aQueryName)
            Dim mqChild As MetaQuery = MetaQuery.GetMetaQueryByName(_aQueryNameChild)

            'Set Where Clause to add Parameters Value
            mq.SQLWhere = "OrderNo = '" + ParamOrderNo + "'"
            mq.FillResultQuery()

            mqChild.SQLWhere = "OrderNo = '" + ParamOrderNo + "'"
            mqChild.FillResultQuery()


            'Add RptPO & RptPODetail DataTables to Dataset
            _aDataset = Nothing
            _aDataset = New DataSet("ReportDataSet")
            _aDataset.Tables.Add(mq.ResultQuery)
            _aDataset.Tables.Add(mqChild.ResultQuery)


            'Add DataRelation between RptPO & RptPODetail
            Dim aParentRelationField As String = mq.GUIDField
            Dim aChildRelationField As String = mq.GUIDField + "_FK"
            Dim aRelation As New DataRelation("RptSO/RptSODetail", mq.ResultQuery.Columns(aParentRelationField), mqChild.ResultQuery.Columns(aChildRelationField))
            _aDataset.Relations.Add(aRelation)


            Dim b As DevExpress.XtraReports.UI.XRBinding

            'Bind Report Controls
            For Each aCol As DataColumn In mq.ResultQuery.Columns
                b = New DevExpress.XtraReports.UI.XRBinding("Text", mq.ResultQuery, aCol.ColumnName)
                Dim aControl As DevExpress.XtraReports.UI.XRControl = CType(Me.FindControl(aCol.ColumnName, True), DevExpress.XtraReports.UI.XRControl)


                If Not aControl Is Nothing Then
                    Try
                        aControl.DataBindings.Add(b)
                    Catch ex As Exception
                    End Try
                End If
            Next


            'Bind Sub Report Controls
            For Each aCol As DataColumn In mqChild.ResultQuery.Columns
                b = New DevExpress.XtraReports.UI.XRBinding("Text", mqChild.ResultQuery, aCol.ColumnName)
                Dim aControl As DevExpress.XtraReports.UI.XRTableCell = CType(Me.FindControl(aCol.ColumnName, True), DevExpress.XtraReports.UI.XRTableCell)

                If Not aControl Is Nothing Then
                    Try
                        aControl.DataBindings.Add(b)
                    Catch ex As Exception
                    End Try
                End If
            Next


            Me.DataSource = _aDataset
            Me.DataMember = _aDataset.Tables(0).TableName

            Me.DetailReport.DataSource = _aDataset
            Me.DetailReport.DataMember = _aDataset.Tables(1).TableName

        Else
            Me.RequestParameters = True
        End If


    End Sub

End Class